﻿using System.Web.Http.Filters;

namespace WebDemo.Filters
{
    public class LogHandleErrorAttribute : ExceptionFilterAttribute 
    {
        public static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public override void OnException(HttpActionExecutedContext filterContext)
        {
            LogException(filterContext);
            base.OnException(filterContext);
        }
        private void LogException(HttpActionExecutedContext exceptionContext)
        {
            Log.Error(string.Format("[{1}]{0}", exceptionContext.Request.RequestUri, exceptionContext.Request.Method), exceptionContext.Exception);
        }
    }
}